/*
 * @Title: 票选优品首页
 * @Author: Jcuiweif
 * @Date:   2018-12-19
 * @Last Modified by:   Jcuiweif
 * @Last Modified time: 2018-12-19
 */
$(document).ready(function(){
  if ($(document).width()<=450){
    var t = $(document).width()/10;
    $("html").css("font-size",t);
    } else {
      $("html").css("font-size",45);
    }
  
  })
var dataInfo = {},
  template = {
    init: function() {
      Vue.use(VueLazyload, {
        preLoad: 1.3,
        error: 'https://h5.meetao.com/img/product/init.png',
        loading: 'https://h5.meetao.com/img/product/init.png',
        attempt: 1
      });
      dataInfo.init = new Vue({
        el: '#app',
        data: {
          width: document.body.offsetWidth,
          tabData: [],
          swiperData: [],
          votebannerdown:[],
          versions: versions,
          icon: {
            normal: '../img/index/shouhui.png',
            active: '../img/index/shouhong.png',
            normal1: '../img/index/gouhui.png',
            active1: '../img/index/gouhong.png',
            active2: '../img/index/myhong.png',
            normal2: '../img/index/myhui.png',
            active3: '../img/index/pthong.png',
            normal3: '../img/index/pthui.png',
            active4:"../img/index/votegoods.png",
            normal4:"../img/index/votegoodsgray.png",
          },
          playicon:'../img/playVideo.png',
          eyes:'../img/voteGoods/eyes.png',
          whtiteeyes:'../img/voteGoods/whtiteeyes.png',
          goodsinfo:'../img/voteGoods/newgoods.png',
          active: 0,
          activeindex:0,
          all: false, //loadOver - show
          all1: false,
          isFx: 1,
          pagesource:1,
          pagenew:1,
          isDz: 0,
          page: 1,
          choose:0,
          limit: 10,
          loading: false,
          isLoading: false,
          finished: false,
          loading1: false,
          isLoading1: false,
          finished1: false,
          listData: [], //商品集合
          navGroup:['又上新了','票选优品','溯源'],
          newgoods:[],
          votedetails:[],
          share:{
            img:'../img/voteGoods/logo100.png',
            noneimg: '../img/404/404.png'
          },
          backsource:[]
        },
        methods: {
          onLoad1: function() {
              dataInfo.init.newgooodsagain();
          },
          onRefresh1: function() { //下拉刷新 
              // this.newgoods = [];
            //  this.pagenew = 1;
            dataInfo.init.all1 = false;
            setTimeout(function() {
                dataInfo.init.newgooodsagain();
            }, 500);
          },
          newgooodsagain:function(){
            ajaxTemplate(addressTest + SERVICE.votenewgoods, function(data) {
              console.log('wewrewr',data);
              var daTa = data.data.result;
              if (data.tag == 0) {
                if (!daTa || daTa.length == 0){
                  // dataInfo.init.$toast('全部加载完');
                  if (dataInfo.init.newgoods.length ==0){
                    // dataInfo.init.nodata= true;
                  } else {
                    dataInfo.init.all1= true;
                  }
                  dataInfo.init.loading1 = false;
                  dataInfo.init.isLoading1 = false;
                  dataInfo.init.finished1 = true;
                  // dataInfo.init.all = true;
                  return;
                }
                dataInfo.init.newgoods = JSON.parse(JSON.stringify(dataInfo.init.newgoods.concat(daTa)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished1 = true;
                  dataInfo.init.all1 = true;
                  console.log(3)
                } else {
                  console.log('有数据')
                  dataInfo.init.finished1 = false;
                }
                dataInfo.init.loading1 = false;
                dataInfo.init.isLoading1 = false;
              } else {
                dataInfo.init.$toast(data.errMsg);
                if (data.errMsg == '未查询到符合条件的商品'){
                  dataInfo.init.loading1 = false;
                  dataInfo.init.isLoading1 = false;
                  dataInfo.init.all1 = true;
                  dataInfo.init.finished1 = true;
                }
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.pagenew++,
            });
          },
          newgooodsagain1:function(){
            ajaxTemplate(addressTest + SERVICE.votenewgoods, function(data) {
              console.log('wewrewr',data);
              var daTa = data.data.result;
              if (data.tag == 0) {
                if (!daTa || daTa.length == 0){
                  // dataInfo.init.$toast('全部加载完');
                  if (dataInfo.init.reback.length ==0){
                    // dataInfo.init.nodata= true;
                  } else {
                    dataInfo.init.all= true;
                  }
                  dataInfo.init.loading = false;
                  dataInfo.init.isLoading = false;
                  dataInfo.init.finished = true;
                  // dataInfo.init.all = true;
                  return;
                }
                dataInfo.init.newgoods = JSON.parse(JSON.stringify(daTa.concat(dataInfo.init.newgoods)));
                console.log(dataInfo.init.newgoods)
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished1 = true;
                  dataInfo.init.all1 = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished1 = false;
                }
                dataInfo.init.loading1 = false;
                dataInfo.init.isLoading1 = false;
              } else {
                dataInfo.init.$toast(data.errMsg);
                if (data.errMsg == '未查询到符合条件的商品'){
                  dataInfo.init.loading1 = false;
                  dataInfo.init.isLoading1 = false;
                  dataInfo.init.all1 = true;
                  dataInfo.init.finished1 = true;
                }
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.pagenew++,
            });
          },
          prodect:function(index){
            // dataInfo.init.newgoods[index]
            // console.log(dataInfo.init.newgoods[index],index)
            if(dataInfo.init.newgoods[index].id){
              location.href ="productDetails.html?isFx=1&isPx=1&productId="+encodeURIComponent(dataInfo.init.newgoods[index].fxVirtualGoodsCode)+'&voteItemNum='+encodeURIComponent(dataInfo.init.newgoods[index].voteActivityIssueNum)+'&voteItemCode='+encodeURIComponent(dataInfo.init.newgoods[index].voteItemCode); 
            }
          }, 
          bannerJump: function(data) { //bannerJump
            if (data.linkRemark == 'product') { //商品 文章 视频 均为跳转内部地址 h5为跳转全链接地址
              jumpProductDetails(data.params);
            } else if (data.linkRemark == 'h5') {
              window.location.href = data.link;
            } else if (data.linkRemark == 'article') {

            } else if (data.linkRemark == 'video') {

            };
          },
          bannerJump2: function(data,index) { //bannerJump
            console.log(data,index,data.linkRemark)
            // window.location.href = data.h5JumpUrl;
            if (index === 0){
              location.href = 'FPtAgainNew.html'
            } else if (index === 2){
              location.href = 'FPtBackSource.html'
            }
          },
          toProduct: function(data) { //toProduct
            jumpProductDetails(data);
          },
          newgoodstab:function(){
            var index = dataInfo.init.activeindex;
            if (index == '0'){
            } else if (index == '1'){
              ajaxTemplate(addressTest + SERVICE.votegoodslist, function(data) {//获取头部banner下part图
                console.log('weweww',data);
                if (data.tag == 0) {
                  // dataInfo.init.votedetails = data.data.result.list;
                  dataInfo.init.$set(dataInfo.init,'votedetails',data.data.result.list);
                } else {
                  dataInfo.init.$toast(data.errMsg);
                };
              }, {
                userId:userId
              });
            } else if (index == '2'){
              
            }
          },
          tabJump: function(data) {
            location.href = "../html/productClassify.html?code=" + data.code + "&name=" + escape(data.name);
          },
          getProductDetails: function() { //获取商品数据
            ajaxTemplate(addressUrl + SERVICE.queryFxGoodsList, function(data) {
              console.log(data);
              var daTa = data.data.result;
              if (data.tag == 0) {
                dataInfo.init.listData = JSON.parse(JSON.stringify(dataInfo.init.listData.concat(daTa)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished = true;
                  dataInfo.init.all = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished = false;
                };
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
                //					是否要有秒杀
                //					daTa.forEach(function(item, index) {
                //						if(item.isKill !== 0) {
                //							dataInfo.init.listData.push(item);
                //						};
                //					});
                //					setTimeout(function() {
                //						var tid = "index" + (daTa.length - 1);
                //						$('#' + tid).ready(function() {
                //							$(".loadImgBox").addClass("rgba").hide();
                //						});
                //					}, 300);
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.page++,
            });
          },
          voteactive: function(ind,event){//投票
            var votedetails = dataInfo.init.votedetails;
            console.log(votedetails)
          },
          votedetailEvent:function(index,event){
            // if (event.target.innerHTML != '投票'){
              var votedetails = dataInfo.init.votedetails;
              location.href='FPtVoteDetails.html?voteItemCode='+votedetails[index].code;
            // }
            // 
          },
          getBanner: function() {
            shareInfo.imgUrl = dataInfo.init.share.img;
          },
        },
      });
      dataInfo.init.getBanner();
    }
  };
template.init();